// 比赛数据相关API

import http from './http';
import type { MatchListParams, MatchListResponse } from '../types/match';

/**
 * 获取比赛列表数据
 * @param params 请求参数 {page, pageSize, dateFilter}
 * @returns 比赛列表数据
 */
export const getMatches = async (params: MatchListParams = {}): Promise<MatchListResponse> => {
  // 设置默认参数
  const defaultParams: MatchListParams = {
    page: 1,
    pageSize: 10,
    dateFilter: 'current'
  };

  // 合并参数
  const queryParams = { ...defaultParams, ...params };
  
  // 构建查询字符串，过滤掉undefined值
  const queryString = Object.entries(queryParams)
    .filter(([value]) => value !== undefined)
    .map(([key, value]) => `${key}=${value}`)
    .join('&');

  return http.get<MatchListResponse['data']>(`/matches?${queryString}`);
};